package com.yami.shop.listener;

import com.yami.shop.common.bean.SensitiveWord;
import com.yami.shop.common.bean.event.GetSensitiveWordEvent;
import com.yami.shop.common.config.Constant;
import com.yami.shop.service.SysConfigService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;


/**
 * @author Citrus
 * @date 2021/8/17 14:19
 */
@Component("getSensitiveWordListener")
@AllArgsConstructor
public class GetSensitiveWordListener {

    private final SysConfigService sysConfigService;

    /**
     * 获取敏感词配置
     */
    @EventListener(GetSensitiveWordEvent.class)
    public void getSensitiveWordListener(GetSensitiveWordEvent event) {
        SensitiveWord sensitiveWord = event.getSensitiveWord();
        SensitiveWord s = sysConfigService.getSysConfigObject(Constant.SENSITIVE_WORDS, SensitiveWord.class);
        sensitiveWord.setSensitiveWord(s.getSensitiveWord());
    }
}
